/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.mzk.oai.metadataRepository.harvest.tei;

import cz.mzk.oai.metadataRepository.harvest.MetadataHarvester;
import cz.mzk.oai.metadataRepository.repository.Identifier;
import cz.mzk.oai.metadataRepository.repository.Repository;
import cz.mzk.oai.metadataRepository.repository.collections.MetadataCollection;
import cz.mzk.oai.metadataRepository.repository.collections.NoCollectionFoundException;

/**
 *
 * @author Martin Řehánek (rehan at mzk.cz)
 */
public abstract class TeiHarvester implements MetadataHarvester {

    private final Repository repository;

    public TeiHarvester(Repository repository) {
        this.repository = repository;
    }

    protected final MetadataCollection findCollection(String collectionName) throws NoCollectionFoundException {
        MetadataCollection collection = repository.findCollection(collectionName);
        if (collection == null) {
            throw new NoCollectionFoundException(collectionName);
        }
        return collection;
    }

    protected final MetadataCollection getOriginalCollection(Identifier id) throws NoCollectionFoundException {
        return repository.selectCollection(id);
    }

    protected final void moveItem(Identifier id, MetadataCollection from, MetadataCollection to) {
        repository.moveItemBetweenCollections(id, from, to);
    }
}
